package com.hxd.otc.module.my.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.base.BaseRecyclerPresenter;
import com.hxd.otc.module.my.adapter.MerchantsOrderAdapter;
import com.hxd.otc.module.my.bean.MerchantsOrderBean;
import com.hxd.otc.module.my.contract.MerchantsOrderContract;
import com.hxd.otc.module.my.model.UserModel;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.utils.DateUtil;

import java.util.ArrayList;
import java.util.Date;

/**
 * Created by lzy on 2018/8/14 0014.
 * description ${商户订单}
 */
public class MerchantsOrderPresenter extends BaseRecyclerPresenter<MerchantsOrderContract.View, MerchantsOrderAdapter, MerchantsOrderBean> implements MerchantsOrderContract.Presenter {

    private final UserModel mUserModel;
    private Date mCreateTime;

    public MerchantsOrderPresenter(MerchantsOrderContract.View view) {
        super(view);
        mUserModel = UserModel.getInstance();
        mCreateTime = new Date();
    }

    @Override
    public void loadData(final boolean isRefresh) {
        mUserModel.businessOrderInfo(DateUtil.format(mCreateTime, "yyyy-MM-dd"), mPageIndex, getPageSize(), new BaseObserver<ArrayList<MerchantsOrderBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<MerchantsOrderBean> merchantsOrderBeans) {
                onLoadDataSuccess(isRefresh, merchantsOrderBeans);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                onLoadDataFail(isRefresh, errMessage);
            }
        }, mView.<BaseBean<ArrayList<MerchantsOrderBean>>>bindAutoDispose());
    }

    public Date getCreateTime() {
        return mCreateTime;
    }

    public void setCreateTime(Date createTime) {
        mCreateTime = createTime;
    }
}
